﻿//
// Copyright (c) 2024 BPer
//

#include <bpercapture/android/BPerVideoCaptureAndroid.h>

#if BPer_OS_ANDROID
#include <iostream>


BPerVideoCaptureAndroid::BPerVideoCaptureAndroid(BPerVideoInfo *pcontext,void* pwindow) {
	m_para = pcontext;
	m_vhandle = new BPerVideoCaptureHandle(pcontext);

	cameraIndex = pcontext->vIndex;
	m_width = m_para->width;
	m_height = m_para->height;
	m_isloop = 0;

	m_pre_videoBuffer=NULL;

	m_camera=new BPerCameraAndroid((ANativeWindow*)pwindow,(BPerCameraType)cameraIndex);
	m_camera->setSize(m_width, m_height);
	m_camera->setUser(m_vhandle);
}

BPerVideoCaptureAndroid::~BPerVideoCaptureAndroid() {
	/*if (m_isloop) {
		stop();
		while (m_isStart) {
			bPer_usleep(1000);
		}
	}*/

	bPer_delete(m_vhandle);
	bPer_delete(m_camera);
}
void BPerVideoCaptureAndroid::setVideoCaptureStart() {
	m_vhandle->m_isCapture = 1;
}
void BPerVideoCaptureAndroid::setVideoCaptureStop() {
	m_vhandle->m_isCapture = 0;
}
int32_t BPerVideoCaptureAndroid::getVideoCaptureState() {
	return m_vhandle->m_isCapture;
}
int32_t BPerVideoCaptureAndroid::getLivingVideoCaptureState() {
	return m_vhandle->m_isLivingCaptrue;
}
int32_t BPerVideoCaptureAndroid::getFilmVideoCaptureState() {
	return m_vhandle->m_isFilm;
}

void BPerVideoCaptureAndroid::setLivingVideoCaptureStart() {
	m_vhandle->m_isLivingCaptrue = 1;
}
void BPerVideoCaptureAndroid::setLivingVideoCaptureStop() {
	m_vhandle->m_isLivingCaptrue = 0;
}

void BPerVideoCaptureAndroid::setFilmVideoCaptureStart() {
	m_vhandle->m_isFilm = 1;
}
void BPerVideoCaptureAndroid::setFilmVideoCaptureStop() {
	m_vhandle->m_isFilm = 0;
}

void BPerVideoCaptureAndroid::setOutVideoBuffer(BPerVideoBuffer *pbuf) {
	m_vhandle->setVideoBuffer(pbuf);
}
void BPerVideoCaptureAndroid::setLivingOutVideoBuffer(BPerVideoBuffer *pbuf) {
	m_vhandle->setLivingVideoBuffer(pbuf);
}
void BPerVideoCaptureAndroid::setFilmOutVideoBuffer(BPerVideoBuffer *pbuf) {
	m_vhandle->setFilmVideoBuffer(pbuf);
}
void BPerVideoCaptureAndroid::setPreVideoBuffer(BPerVideoBuffer *pbuf) {
	m_pre_videoBuffer=pbuf;
	m_vhandle->setPreVideoBuffer(pbuf);
}
void BPerVideoCaptureAndroid::initstamp() {
	m_vhandle->initstamp();
}
int32_t BPerVideoCaptureAndroid::setPara() {

	return BPer_Ok;
}

int32_t BPerVideoCaptureAndroid::init() {
	if(m_camera) m_camera->initCamera();
	return BPer_Ok;
}

void BPerVideoCaptureAndroid::stopLoop() {
	m_isloop = 0;
}

void BPerVideoCaptureAndroid::startLoop() {

	m_isloop = 1;
	m_vhandle->m_start_time = 0;

	m_isloop=0;

}
#endif
